#include "StdAfx.h"
#include "Line.h"

Line::Line(void)
{
}

Line::~Line(void)
{
}


void Line::moveLeft()
{
	translationMatrix.SetTranslation(-TRANSLATE_STEP, 0, 0);
	move();
}
void Line::moveRight()
{
	translationMatrix.SetTranslation(TRANSLATE_STEP, 0, 0);
	move();
}
void Line::moveForward()
{
	translationMatrix.SetTranslation(0, 0, TRANSLATE_STEP);
	move();
}
void Line::moveBackward()
{
	translationMatrix.SetTranslation(0, 0, -TRANSLATE_STEP);
	move();
}

void Line::RotateLeft()
{
	rotationMatrix.SetRotationY(-ROTATE_STEP);
	rotate();
}
void Line::RotateRight()
{
	rotationMatrix.SetRotationY(ROTATE_STEP);
	rotate();
}
void Line::RotateUp()
{ 
	rotationMatrix.SetRotationZ(ROTATE_STEP);
	rotate();
}
void Line::RotateDown()
{
	rotationMatrix.SetRotationZ(-ROTATE_STEP);
	rotate();
}

void Line::move()
{
	//position = Vector4(position, 1) * translationMatrix * worldMatrix;
	worldMatrix = worldMatrix * translationMatrix;
}

void Line::rotate()
{
	//position = Vector4(position, 1) * rotationMatrix * worldMatrix;
	worldMatrix = worldMatrix * rotationMatrix;
}

void Line::Draw( ESContext *esContext, Shaders* myShaders, Camera* camera)
{
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
	glEnableVertexAttribArray(myShaders->positionAttribute);
	glVertexAttribPointer(myShaders->positionAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
	glEnableVertexAttribArray(myShaders->colorAtttribute);
	glVertexAttribPointer(myShaders->colorAtttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (char*)0 + sizeof(Vector3));
	
	
	//Pass WorldMatrix
	glUniformMatrix4fv(myShaders->matViewUniform, 1, GL_FALSE, &(camera->getViewMatrix().Transpose().m[0][0]));
	glUniformMatrix4fv(myShaders->matProjectionUniform, 1, GL_FALSE, &(camera->getProjectionMatrix().Transpose().m[0][0]));
	glUniformMatrix4fv(myShaders->matWorldUniform, 1, GL_FALSE, &(worldMatrix.Transpose().m[0][0]));
	
	
	glDrawArrays(GL_LINES, 0, 3);
}

void Line::Update ( ESContext *esContext, float deltaTime)
{

}